package ed.hbut.supermarket1.mapper;

import ed.hbut.supermarket1.entity.Merchandise;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MerchandiseMapper {

    @Insert("insert into merchandise(MerchandiseName, MerchandisePrice, MerchandiseCategoryName, MerchandiseState, MerchandiseCategoryID, MerchandiseGoodsID) value (#{merchandiseName}, #{merchandisePrice}, #{merchandiseCategoryName}, #{merchandiseState},#{merchandiseCategoryId},#{merchandiseGoodsId});")
    void insertMerchandise(Merchandise merchandise);

    @Select("select * from merchandise")
    List<Merchandise> getAllMerchandise();

    @Select("select * from merchandise where MerchandiseID=#{id}")
    Merchandise getById(Integer id);

    @Delete("delete from merchandise where MerchandiseID=#{id}")
    void deleteById(Integer id);

    @Update("update merchandise set MerchandiseName=#{merchandiseName}, MerchandisePrice=#{merchandisePrice}, MerchandiseCategoryName=#{merchandiseCategoryName}, MerchandiseState=#{merchandiseState}, MerchandiseCategoryID=#{merchandiseCategoryId}, MerchandiseGoodsID=#{merchandiseGoodsId} where MerchandiseID=#{merchandiseId}")
    void update(Merchandise merchandise);

    @Select("select category.CategoryName from category where CategoryID=#{merchandiseCategoryId}")
    String getCategoryName(Integer merchandiseCategoryId);


    @Select("select MerchandiseCategoryID from merchandise where MerchandiseID=#{id}")
    Integer getCategoryId(Integer id);
}
